package com.cy.dda.web.admin.goodsdiligencing;

import com.cy.dda.model.PageBean;
import com.cy.dda.model.Result;
import com.cy.dda.model.ao.goodsdiligencing.GoodsDiligencingReportAuditAO;
import com.cy.dda.model.enums.goodsdiligencing.GoodsDiligencingType;
import com.cy.dda.model.query.goodsdiligencing.GoodsDiligencingAdminListQuery;
import com.cy.dda.model.vo.goodsdiligencing.GoodsDiligencingAdminDetailVO;
import com.cy.dda.model.vo.goodsdiligencing.GoodsDiligencingAdminListVO;
import com.cy.dda.service.goodsdiligencing.GoodsDiligencingService;
import com.cy.dda.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 后台-家具尽调 controller
 * @Author tanyilin
 * @Date 2019/8/29 15:14
 */
@RestController
@RequestMapping("/admin/goods/diligencing")
@Api(tags = "后台-家具尽调 controller")
public class AdminGoodsDiligencingController extends BaseController {

    @Autowired
    private GoodsDiligencingService goodsDiligencingService;

    @ApiOperation("客户列表")
    @GetMapping("/get/customer/list")
    public PageBean<GoodsDiligencingAdminListVO> getCustomerList(GoodsDiligencingAdminListQuery query) {
        query.setFlag(null);
        PageBean<GoodsDiligencingAdminListVO> pageBean = goodsDiligencingService.getGoodsDiligencingAdminList(query);
        return pageBean;
    }

    @ApiOperation("’调查中‘列表")
    @GetMapping("/get/uncompleted/list")
    public PageBean<GoodsDiligencingAdminListVO> getUncompletedList(GoodsDiligencingAdminListQuery query) {

        query.setFlag(1);
        PageBean<GoodsDiligencingAdminListVO> pageBean = goodsDiligencingService.getGoodsDiligencingAdminList(query);
        return pageBean;
    }

    @ApiOperation("‘待审核’列表")
    @GetMapping("/get/confirmWait/list")
    public PageBean<GoodsDiligencingAdminListVO> getConfirmWaitList(GoodsDiligencingAdminListQuery query) {

        query.setFlag(2);
        PageBean<GoodsDiligencingAdminListVO> pageBean = goodsDiligencingService.getGoodsDiligencingAdminList(query);
        return pageBean;
    }

    @ApiOperation("‘已确认’列表")
    @GetMapping("/get/completed/list")
    public PageBean<GoodsDiligencingAdminListVO> getCompletedList(GoodsDiligencingAdminListQuery query) {

        query.setFlag(3);
        PageBean<GoodsDiligencingAdminListVO> pageBean = goodsDiligencingService.getGoodsDiligencingAdminList(query);
        return pageBean;
    }

    @ApiOperation("分配")
    @PostMapping("/do/appoint/distribute")
    public Result appointDistribute(@RequestParam(value = "goodsDiligencingId") Long goodsDiligencingId,
                                    @RequestParam(value = "diligencingType") GoodsDiligencingType diligencingType,
                                    @RequestParam(value = "userId") Long userId) {
        goodsDiligencingService.appointDistributeGoodsDiligencing(goodsDiligencingId, diligencingType, userId);
        return ok();
    }

    @ApiOperation("审核尽调报告")
    @PostMapping("/do/audit/report")
    public Result doAuditReport(@Validated GoodsDiligencingReportAuditAO auditAO, BindingResult bindingResult) {

        this.checkError(bindingResult);
        goodsDiligencingService.doAuditGoodsDiligencingReport(auditAO, this.getManager().getManagerId());
        return ok();
    }

    @ApiOperation("尽调资料-详情")
    @GetMapping("/get/detail")
    public Result<GoodsDiligencingAdminDetailVO> getDetail(@RequestParam(value = "goodsDiligencingId") Long goodsDiligencingId) {

        GoodsDiligencingAdminDetailVO detailVO = goodsDiligencingService.getGoodsDiligencingAdminDetail(goodsDiligencingId);
        return ok("查询成功", detailVO);
    }

    @ApiOperation("申请资料")
    @GetMapping("/get/apply/info")
    public Result getApplyInfo(@RequestParam(value = "goodsDiligencingId") Long goodsDiligencingId) {

        return goodsDiligencingService.getGoodsDiligencingApplyInfo(goodsDiligencingId);
    }

}
